﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class ResumeSearchAdvanced : System.Web.UI.Page
{
    string mode = "Advanced";
    string redirectlink = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Fillddls();

        }
    }
    protected void btnAdvancedSeach_Click(object sender, EventArgs e)
    {
        mode = clsEncryptionDecryption.EncryptQueryString(mode);
        redirectlink += "ResumeSearchResult.aspx?mode=" + mode;
        if (txtKeySkills.Text != "")
            redirectlink += "&skillset=" + clsEncryptionDecryption.EncryptQueryString(txtKeySkills.Text);
        if (txtIndustry.Text != "")
            redirectlink += "&industryset=" + clsEncryptionDecryption.EncryptQueryString(txtIndustry.Text);
        if (ddlFunctionalArea.SelectedIndex != 0)
            redirectlink += "&functionalarea=" + clsEncryptionDecryption.EncryptQueryString(ddlFunctionalArea.SelectedValue);
        if (ddlMinExpRequired.SelectedIndex != 0)
            redirectlink += "&experience=" + clsEncryptionDecryption.EncryptQueryString(ddlMinExpRequired.SelectedValue);
        if (ddlJobLocation.SelectedIndex != 0)
            redirectlink += "&joblocation=" + clsEncryptionDecryption.EncryptQueryString(ddlJobLocation.SelectedValue);
    }
    protected void btnClearSearch_Click(object sender, EventArgs e)
    {
        try
        {
            txtKeySkills.Text = "";
            grdAdvancedSearch.DataSource = null;
            grdAdvancedSearch.DataBind();
        }
        catch (Exception)
        {

            throw;
        }
    }

    protected void Fillddls()
    {
        try
        {
            // Project Location
            clsCity objclsCity = new clsCity();
            List<IN_TB_CITY> objIN_TB_CITY = new List<IN_TB_CITY>();
            objIN_TB_CITY = objclsCity.GetAllCities();
            ddlJobLocation.Items.Clear();
            ddlJobLocation.AppendDataBoundItems = true;
            ddlJobLocation.DataTextField = "CITY";
            ddlJobLocation.DataValueField = "ID";
            ddlJobLocation.Items.Add("Select");
            ddlJobLocation.Items[0].Value = "0";
            ddlJobLocation.DataSource = objIN_TB_CITY;
            ddlJobLocation.DataBind();

            // Functional Area
            clsFunctionalAreaDAL objclsFunctionalAreaDAL = new clsFunctionalAreaDAL();
            List<IN_TB_FUNCTIONAL_AREA> objIN_TB_FUNCTIONAL_AREA = new List<IN_TB_FUNCTIONAL_AREA>();
            objIN_TB_FUNCTIONAL_AREA = objclsFunctionalAreaDAL.GetAllFunctionalAreas();
            ddlFunctionalArea.Items.Clear();
            ddlFunctionalArea.AppendDataBoundItems = true;
            ddlFunctionalArea.DataTextField = "FUNCTIONAL_AREA";
            ddlFunctionalArea.DataValueField = "ID";
            ddlFunctionalArea.Items.Add("Select");
            ddlFunctionalArea.Items[0].Value = "0";
            ddlFunctionalArea.DataSource = objIN_TB_FUNCTIONAL_AREA;
            ddlFunctionalArea.DataBind();

            //Min Experience Required
            ddlMinExpRequired.Items.Clear();
            ddlMinExpRequired.AppendDataBoundItems = true;
            ddlMinExpRequired.Items.Add("Select");
            ddlMinExpRequired.Items[0].Value = "0";
            for (int i = 1; i <= 90; i++)
            {
                ddlMinExpRequired.Items.Add(i.ToString());
                ddlMinExpRequired.Items[i].Value = i.ToString();
            }
            ddlMinExpRequired.DataBind();

        }
        catch (Exception)
        {

            throw;
        }
    }

    //protected void grdAdvancedSearch_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    try
    //    {
    //        if (e.Row.RowType == DataControlRowType.DataRow)
    //        {
    //            //Getting Job Location
    //            int Job_locationId = Convert.ToInt32(e.Row.Cells[8].Text);
    //            clsCity objclsCity = new clsCity();
    //            IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
    //            objIN_TB_CITY = objclsCity.GetCityById(Job_locationId);
    //            e.Row.Cells[8].Text = objIN_TB_CITY.CITY;

    //            //Getting Preferred Location
    //            int Preferred_locationId = Convert.ToInt32(e.Row.Cells[11].Text);
    //            objclsCity = new clsCity();
    //            objIN_TB_CITY = new IN_TB_CITY();
    //            objIN_TB_CITY = objclsCity.GetCityById(Preferred_locationId);
    //            e.Row.Cells[11].Text = objIN_TB_CITY.CITY;

    //            // Geting Functional Area
    //            int Functional_AreaId = Convert.ToInt32(e.Row.Cells[10].Text);
    //            clsFunctionalAreaDAL objclsFunctionalAreaDAL = new clsFunctionalAreaDAL();
    //            IN_TB_FUNCTIONAL_AREA objIN_TB_FUNCTIONAL_AREA = new IN_TB_FUNCTIONAL_AREA();
    //            objIN_TB_FUNCTIONAL_AREA = objclsFunctionalAreaDAL.GetAllFunctionalAreaById(Functional_AreaId);
    //            e.Row.Cells[10].Text = objIN_TB_FUNCTIONAL_AREA.FUNCTIONAL_AREA;

    //            ImageButton lnkDownloadCV = (ImageButton)e.Row.FindControl("lnkDownloadCV");
    //            Label lblDownload = (Label)e.Row.FindControl("lblDownload");
    //            clsEmployerDAL objclsEmployerDAL = new clsEmployerDAL();

    //            if (Session["EmployerId"] != null)
    //            {
    //                IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST = new IN_TB_EMPLOYER_MST();
    //                objIN_TB_EMPLOYER_MST = objclsEmployerDAL.GetEmployerById(Convert.ToInt32(Session["EmployerId"].ToString()));
    //                if (objIN_TB_EMPLOYER_MST != null)
    //                {
    //                    DateTime DownloadTill = Convert.ToDateTime(objIN_TB_EMPLOYER_MST.DOWNLOAD_TILL);
    //                    if (DownloadTill.Date < DateTime.Today.Date)
    //                    {
    //                        lnkDownloadCV.Enabled = false;
    //                        lblDownload.Text = "Download Limit Exceeded";
    //                    }
    //                    else
    //                    {
    //                        lblDownload.Text = "";
    //                    }
    //                }
    //            }

    //        }
    //    }
    //    catch (Exception)
    //    {

    //        throw;
    //    }
    //}
    protected void grdAdvancedSearch_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ViewCV")
        {
            if (Session["UserId"] != null)
            {
                string UserId = Convert.ToString(e.CommandArgument);
                clsSearchResume objclsSearchResume = new clsSearchResume();
                clsResumeSearchResultBo objclsResumeSearchResultBo = new clsResumeSearchResultBo();
                objclsResumeSearchResultBo = objclsSearchResume.GetResumeByUserId(Convert.ToInt32(UserId));

                if (objclsResumeSearchResultBo != null)
                {
                    redirectlink = "ResumeDetails.aspx?userid=" + Convert.ToString(e.CommandArgument);
                    string skillset = Convert.ToString(objclsResumeSearchResultBo.SKILL_SET);
                    if (skillset != "" && skillset != null)
                    {
                        skillset = clsEncryptionDecryption.EncryptQueryString(skillset);
                        redirectlink += "&skillset=" + skillset;
                    }
                    string email = Convert.ToString(objclsResumeSearchResultBo.EMAIL);
                    if (email != "" && email != null)
                    {
                        email = clsEncryptionDecryption.EncryptQueryString(email);
                        redirectlink += "&email=" + email;
                    }
                    string mobile = Convert.ToString(objclsResumeSearchResultBo.MOBILE);
                    if (mobile != "" && mobile != null)
                    {
                        mobile = clsEncryptionDecryption.EncryptQueryString(mobile);
                        redirectlink += "&mobile=" + mobile;
                    }
                    string phone = Convert.ToString(objclsResumeSearchResultBo.PHONE);
                    if (phone != "" && phone != null)
                    {
                        phone = clsEncryptionDecryption.EncryptQueryString(phone);
                        redirectlink += "&phone=" + phone;
                    }
                    string experience = Convert.ToString(objclsResumeSearchResultBo.EXPERIENCE);
                    if (experience != "" && experience != null)
                    {
                        experience = clsEncryptionDecryption.EncryptQueryString(experience);
                        redirectlink += "&experience=" + experience;
                    }
                    string currentcomp = Convert.ToString(objclsResumeSearchResultBo.CURRENT_COMPANY);
                    if (currentcomp != "" && currentcomp != null)
                    {
                        currentcomp = clsEncryptionDecryption.EncryptQueryString(currentcomp);
                        redirectlink += "&currentcomp=" + currentcomp;
                    }
                    string currentdesig = Convert.ToString(objclsResumeSearchResultBo.CURRENT_POST);
                    if (currentdesig != "" && currentdesig != null)
                    {
                        currentdesig = clsEncryptionDecryption.EncryptQueryString(currentdesig);
                        redirectlink += "&currentdesig=" + currentdesig;
                    }
                    string currentloc = Convert.ToString(objclsResumeSearchResultBo.CURRENT_LOCATION);
                    if (currentloc != "" && currentloc != null)
                    {
                        currentloc = clsEncryptionDecryption.EncryptQueryString(currentloc);
                        redirectlink += "&currentloc=" + currentloc;
                    }
                    string currentctc = Convert.ToString(objclsResumeSearchResultBo.CURRENT_CTC);
                    if (currentctc != "" && currentctc != null)
                    {
                        currentctc = clsEncryptionDecryption.EncryptQueryString(currentctc);
                        redirectlink += "&currentloc=" + currentloc;
                    }
                    string functionalarea = Convert.ToString(objclsResumeSearchResultBo.FUNCTIONAL_AREA);
                    if (functionalarea != "" && functionalarea != null)
                    {
                        functionalarea = clsEncryptionDecryption.EncryptQueryString(functionalarea);
                        redirectlink += "&functionalarea=" + functionalarea;
                    }
                    string preferredlocation = Convert.ToString(objclsResumeSearchResultBo.PREFERRED_LOCATION);
                    if (preferredlocation != "" && preferredlocation != null)
                    {
                        preferredlocation = clsEncryptionDecryption.EncryptQueryString(preferredlocation);
                        redirectlink += "&preferredlocation=" + preferredlocation;
                    }
                    string cvpath = Convert.ToString(objclsResumeSearchResultBo.CV_PATH);
                    if (cvpath != "" && cvpath != null)
                    {
                        cvpath = clsEncryptionDecryption.EncryptQueryString(cvpath);
                        redirectlink += "&cvpath=" + cvpath;
                    }
                    string downloadtill = Convert.ToString(objclsResumeSearchResultBo.DOWNLOAD_TILL);
                    if (downloadtill != "" && downloadtill != null)
                    {
                        downloadtill = clsEncryptionDecryption.EncryptQueryString(downloadtill);
                        redirectlink += "&downloadtill=" + downloadtill;
                    }
                    Response.Redirect(redirectlink);
                }
            }
            else
            {
                Response.Redirect("EmployerLogin.aspx");
            }
        }
    }



}